package com.web.dao;

import com.github.pagehelper.Page;
import com.web.controller.web.WebAgentHomeController;
import com.web.controller.web.WebWithdrawController;
import com.web.entity.AgentWithdrawApply;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

/**
 * @author FDjavaone
 */
public interface AgentWithdrawApplyMapper {
    @Delete({
        "delete from t_agent_withdraw_apply",
        " where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into t_agent_withdraw_apply (u_id, name,",
        " phone, account, ",
        " amt, bank_name, card_no, ",
        " poundage_rate, poundage, ",
        " status, reason, record_id, ",
        " create_time, modify_time)",
        " values (#{uId,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, ",
        " #{phone,jdbcType=VARCHAR}, #{account,jdbcType=VARCHAR}, ",
        " #{amt,jdbcType=DECIMAL}, #{bankName,jdbcType=VARCHAR}, #{cardNo,jdbcType=VARCHAR}, ",
        " #{poundageRate,jdbcType=DECIMAL}, #{poundage,jdbcType=DECIMAL}, ",
        " #{status,jdbcType=INTEGER}, #{reason,jdbcType=VARCHAR},#{recordId,jdbcType=BIGINT}, ",
        " #{createTime,jdbcType=TIMESTAMP}, #{modifyTime,jdbcType=TIMESTAMP})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
    int insert(AgentWithdrawApply record);

    @InsertProvider(type=AgentWithdrawApplySqlProvider.class, method="insertSelective")
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
    int insertSelective(AgentWithdrawApply record);

    @Select({
        "select",
        " id, u_id, name, phone, account, amt, bank_name, card_no, poundage_rate, poundage, ",
        " status, reason, record_id, create_time, modify_time",
        " from t_agent_withdraw_apply",
        " where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="u_id", property="uId", jdbcType=JdbcType.BIGINT),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="phone", property="phone", jdbcType=JdbcType.VARCHAR),
        @Result(column="account", property="account", jdbcType=JdbcType.VARCHAR),
        @Result(column="amt", property="amt", jdbcType=JdbcType.DECIMAL),
        @Result(column="bank_name", property="bankName", jdbcType=JdbcType.VARCHAR),
        @Result(column="card_no", property="cardNo", jdbcType=JdbcType.VARCHAR),
        @Result(column="poundage_rate", property="poundageRate", jdbcType=JdbcType.DECIMAL),
        @Result(column="poundage", property="poundage", jdbcType=JdbcType.DECIMAL),
        @Result(column="status", property="status", jdbcType=JdbcType.INTEGER),
        @Result(column="reason", property="reason", jdbcType=JdbcType.VARCHAR),
        @Result(column="record_id", property="recordId", jdbcType=JdbcType.BIGINT),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="modify_time", property="modifyTime", jdbcType=JdbcType.TIMESTAMP)
    })
    AgentWithdrawApply selectByPrimaryKey(Long id);

    @UpdateProvider(type=AgentWithdrawApplySqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(AgentWithdrawApply record);

    @Update({
        "update t_agent_withdraw_apply",
        " set u_id = #{uId,jdbcType=BIGINT},",
          " name = #{name,jdbcType=VARCHAR},",
          " phone = #{phone,jdbcType=VARCHAR},",
          " account = #{account,jdbcType=VARCHAR},",
          " amt = #{amt,jdbcType=DECIMAL},",
          " bank_name = #{bankName,jdbcType=VARCHAR},",
          " card_no = #{cardNo,jdbcType=VARCHAR},",
          " poundage_rate = #{poundageRate,jdbcType=DECIMAL},",
          " poundage = #{poundage,jdbcType=DECIMAL},",
          " status = #{status,jdbcType=INTEGER},",
          " reason = #{reason,jdbcType=VARCHAR},",
          " record_id = #{recordId,jdbcType=BIGINT},",
          " create_time = #{createTime,jdbcType=TIMESTAMP},",
          " modify_time = #{modifyTime,jdbcType=TIMESTAMP}",
        " where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(AgentWithdrawApply record);

    @SelectProvider(type = AgentWithdrawApplySqlProvider.class, method = "selectMyWithdraws")
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
            @Result(column="u_id", property="uId", jdbcType=JdbcType.BIGINT),
            @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
            @Result(column="phone", property="phone", jdbcType=JdbcType.VARCHAR),
            @Result(column="account", property="account", jdbcType=JdbcType.VARCHAR),
            @Result(column="amt", property="amt", jdbcType=JdbcType.DECIMAL),
            @Result(column="bank_name", property="bankName", jdbcType=JdbcType.VARCHAR),
            @Result(column="card_no", property="cardNo", jdbcType=JdbcType.VARCHAR),
            @Result(column="poundage_rate", property="poundageRate", jdbcType=JdbcType.DECIMAL),
            @Result(column="poundage", property="poundage", jdbcType=JdbcType.DECIMAL),
            @Result(column="status", property="status", jdbcType=JdbcType.INTEGER),
            @Result(column="reason", property="reason", jdbcType=JdbcType.VARCHAR),
            @Result(column="record_id", property="recordId", jdbcType=JdbcType.BIGINT),
            @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="modify_time", property="modifyTime", jdbcType=JdbcType.TIMESTAMP)
    })
    Page<AgentWithdrawApply> selectMyWithdraws(WebAgentHomeController.AgentWithdrawColumns withdrawColumns);


    @SelectProvider(type = AgentWithdrawApplySqlProvider.class, method = "selectAllwithdraws")
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
            @Result(column="u_id", property="uId", jdbcType=JdbcType.BIGINT),
            @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
            @Result(column="phone", property="phone", jdbcType=JdbcType.VARCHAR),
            @Result(column="account", property="account", jdbcType=JdbcType.VARCHAR),
            @Result(column="amt", property="amt", jdbcType=JdbcType.DECIMAL),
            @Result(column="bank_name", property="bankName", jdbcType=JdbcType.VARCHAR),
            @Result(column="card_no", property="cardNo", jdbcType=JdbcType.VARCHAR),
            @Result(column="poundage_rate", property="poundageRate", jdbcType=JdbcType.DECIMAL),
            @Result(column="poundage", property="poundage", jdbcType=JdbcType.DECIMAL),
            @Result(column="status", property="status", jdbcType=JdbcType.INTEGER),
            @Result(column="reason", property="reason", jdbcType=JdbcType.VARCHAR),
            @Result(column="record_id", property="recordId", jdbcType=JdbcType.BIGINT),
            @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="modify_time", property="modifyTime", jdbcType=JdbcType.TIMESTAMP)
    })
    Page<AgentWithdrawApply> selectAllwithdraws(WebWithdrawController.WithdrawColumns withdrawColumns);

    @Select({
            "select count(0) from t_agent_withdraw_apply where status=0 "
    })
    int countWaiting();
}